<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书管理</title>
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/css/dsb.css">
</head>
<body>

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand one-pan-link-mark" href="/logout/">退出登陆</a>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li class=""><a href="/index" class="one-pan-link-mark">基本信息</a></li>
                <li class=""><a href="/course" class="one-pan-link-mark">选课信息</a></li>
                <li class=""><a href="/mark" class="one-pan-link-mark">成绩信息</a></li>
                <li class=""><a href="/money" class="one-pan-link-mark">消费信息</a></li>
                <li class=""><a href="/book" class="one-pan-link-mark">图书借阅</a></li>
                <li class="active"><a href="/all_books/" class="one-pan-link-mark">图书管理</a></li>
                <li class=""><a href="/course_manage" class="one-pan-link-mark">课程管理</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="d-flex justify-content-between align-items-center">
                <h2 class="sub-header" style="display: inline-block; margin-right: 20px;">图书管理</h2>
                <div style="display: inline-block;">
                    <a href="/add_book/" class="btn btn-success">添加图书</a>
                </div>
            </div>
            
            {% if request.GET.success %}
            <div class="alert alert-success">
                {{ request.GET.success }}
            </div>
            {% endif %}
            
            {% if request.GET.error %}
            <div class="alert alert-danger">
                {{ request.GET.error }}
            </div>
            {% endif %}
            
{#            {% if error_message %}#}
{#            <div class="alert alert-danger">#}
{#                {{ error_message }}#}
{#            </div>#}
{#            {% endif %}#}
            
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>书号</th>
                        <th>书名</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% if books %}
                        {% for book in books %}
                        <tr>
                            <td>{{ forloop.counter }}</td>
                            <td>{{ book.bo_num }}</td>
                            <td>{{ book.bo_name }}</td>
                            <td>
                                {% if book.bo_num in borrowed_book_ids %}
                                    <span class="label label-warning">借阅中</span>
                                {% else %}
                                    <span class="label label-success">可借阅</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if book.bo_num in borrowed_book_ids %}
                                    <a href="#" class="btn btn-primary btn-sm disabled" title="该书籍已被借阅">借阅</a>
                                {% else %}
                                    <a href="/borrow_book/{{ book.bo_num }}/" class="btn btn-primary btn-sm">借阅</a>
                                {% endif %}
                                <a href="/edit_book/{{ book.bo_num }}/" class="btn btn-warning btn-sm">修改</a>
                                <a href="#" class="btn btn-danger btn-sm" onclick="confirmDelete({{ book.bo_num }}, '{{ book.bo_name }}')">删除</a>
                            </td>
                        </tr>
                        {% endfor %}
                    {% else %}
                        <tr>
                            <td colspan="5" class="text-center">暂无书籍信息</td>
                        </tr>
                    {% endif %}
                    </tbody>
                </table>
            </div>
            
            <div class="text-center" style="margin-top: 20px;">
                <a href="/book/" class="btn btn-default">返回借阅记录</a>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    // 获取所有的提示消息
    var alerts = document.querySelectorAll('.alert');
    
    // 为每个提示消息设置3秒后自动隐藏
    alerts.forEach(function(alert) {
        setTimeout(function() {
            alert.style.transition = 'opacity 1s';
            alert.style.opacity = '0';
            setTimeout(function() {
                alert.style.display = 'none';
            }, 1000);
        }, 3000);
    });
</script>
<script>
    // 确认删除函数
    function confirmDelete(bookId, bookName) {
        if (confirm("确定要删除《" + bookName + "》吗？此操作不可恢复！")) {
            window.location.href = "/delete_book/" + bookId + "/";
        }
    }
</script>
</html> 